package com.zgx.plus.system.controller.system;

import com.zgx.plus.common.aop.Log;
import com.zgx.plus.common.base.BaseController;
import com.zgx.plus.common.enums.BusinessType;
import com.zgx.plus.common.response.R;
import com.zgx.plus.common.response.page.TableDataInfo;
import com.zgx.plus.system.api.pos.SysDictData;
import com.zgx.plus.system.api.vos.SysDictDataVo;
import com.zgx.plus.system.service.SysDictDataService;
import com.zgx.plus.system.service.SysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 数据字典信息
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController {
    @Autowired
    private SysDictDataService dictDataService;

    @Autowired
    private SysDictTypeService dictTypeService;

    @PreAuthorize("@ss.hasPermi('system:dict:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDictDataVo dictData) {
        startPage();
        return getDataTable(dictDataService.selectDictDataList(dictData));
    }

    @Log(title = "字典数据", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:dict:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDictData dictData) {
//        List<SysDictData> list = dictDataService.selectDictDataList(dictData);
//        ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
//        util.exportExcel(response, list, "字典数据");
    }

    /**
     * 查询字典数据详细
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:dict:query')")
    @GetMapping(value = "/{dictCode}")
    public R<SysDictDataVo> getInfo(@PathVariable Long dictCode) {
        return R.ok(dictDataService.selectDictDataById(dictCode));
    }
//
//    /**
//     * 根据字典类型查询字典数据信息
//     * @return
//     */
//    @GetMapping(value = "/type/{dictType}")
//    public R<List<SysDictData>> dictType(@PathVariable String dictType) {
//        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
//        if (Objects.isNull(data)) {
//            data = new ArrayList<>();
//        }
//        return R.ok(data);
//    }
//
//    /**
//     * 新增字典类型
//     * @return
//     */
//    @PreAuthorize("@ss.hasPermi('system:dict:add')")
//    @Log(title = "字典数据", businessType = BusinessType.INSERT)
//    @PostMapping
//    public R<Integer> add(@Validated @RequestBody SysDictData dict) {
//        dict.setCreateBy(getUsername());
//        return R.ok(dictDataService.insertDictData(dict));
//    }
//
//    /**
//     * 修改保存字典类型
//     * @return
//     */
//    @PreAuthorize("@ss.hasPermi('system:dict:edit')")
//    @Log(title = "字典数据", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public R<Integer> edit(@Validated @RequestBody SysDictData dict) {
//        dict.setUpdateBy(getUsername());
//        return R.ok(dictDataService.updateDictData(dict));
//    }
//
//    /**
//     * 删除字典类型
//     */
//    @PreAuthorize("@ss.hasPermi('system:dict:remove')")
//    @Log(title = "字典类型", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{dictCodes}")
//    public R<String> remove(@PathVariable Long[] dictCodes) {
//        dictDataService.deleteDictDataByIds(dictCodes);
//        return R.ok();
//    }
}
